#当前处于E:\学习\python下
#第二个参数默认读模式 open会返回一个文件对象
f = open("./data.txt","r",encoding="utf-8")
content = f.read()
print(content)
#读完文件后 不要忘记close
f.close()

#不用加close 使用 with as 读完自动close
with open("./data.txt","r",encoding="utf-8") as f1:
    content = f1.read()
    print(content)

#写文件 如果没有poem.txt会自动创建
with open("./poem.txt","w",encoding="utf-8") as f2:
    f2.write("早\n上\n好")
#在文件后追加内容 如果用"w"会覆盖之前写的 用a来追加
with open("./poem.txt","a",encoding="utf-8") as f3:
    f3.write("晚\n上\n好")